package com.jiufengxinxi.ts.device.equipment;

import java.util.Arrays;

public class CL3000 {
	
	
	
	public static void main(String[] args) {
		String str="1B 24 4C 59 4D 49 4E 00 00 BA FF FF FF FF 21 00 54 02 00 00 00 00 80 00 20 00 00 00 00 00 01 00 48 69 C4 E3 BA C3 A3 AC C9 EE DB DA C0 F8 D1 D0 00";
		String s = str.replace(" ", "");
		//System.out.println(hexToByteArray(s).toString());
		
		//System.out.println(bts.length);
		System.out.println(Arrays.toString(hexToByteArray(s)));
		//String s="27, 36, 76, 89, 77, 73, 78, 0, 0, -70, -1, -1, -1, -1, 33, 0, 84, 2, 0, 0, 0, 0, -128, 0, 32, 0, 0, 0, 0, 0, 1, 0, 72, 105, -60, -29, -70, -61, -93, -84, -55, -18, -37, -38, -64, -8, -47, -48, 0, 9, -14";
		//System.out.println(s.replace(",", ""));
	}
	
	
/*	private static byte[] HexStringToByte(String hex)
    {
        int num = hex.length() / 2;
        byte[] buffer = new byte[num];
        char[] chArray = hex.toCharArray();
        for (int i = 0; i < num; i++)
        {
            int index = i * 2;
            byte b = (byte)((ToByte(chArray[index]) << 4) | ToByte(chArray[index + 1]));
            if(b<(byte)0){
            	b += 256;
            }
            buffer[i] = b;
        }
        return buffer;
    }
*/	
	/*private static int ToByte(char c)
    {
        return (byte)"0123456789ABCDEF".indexOf(c);
    }*/
	
	public static byte[] hexToByteArray(String inHex){  
	    int hexlen = inHex.length();  
	    byte[] result;  
	    if (hexlen % 2 == 1){  
	        //奇数  
	        hexlen++;  
	        result = new byte[(hexlen/2)];  
	        inHex="0"+inHex;  
	    }else {  
	        //偶数  
	        result = new byte[(hexlen/2)];  
	    }  
	    int j=0;  
	    for (int i = 0; i < hexlen; i+=2){  
	        result[j]=hexToByte(inHex.substring(i,i+2));  
	        j++;  
	    }  
	    return result;   
	}
	

public static byte hexToByte(String inHex){  
   return (byte)Integer.parseInt(inHex,16);  
} 
}
